package cn.hua.trip.admin.controller;

import cn.hua.trip.base.domain.StrategyCatalog;
import cn.hua.trip.base.query.StrategyCatalogQueryObject;
import cn.hua.trip.base.service.IStrategyCatalogService;
import cn.hua.trip.base.service.IStrategyService;
import cn.hua.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/strategyCatalog")
public class StrategyCatalogController {
    @Autowired
    private IStrategyCatalogService strategyCatalogService;

    @Autowired
    private IStrategyService strategyService;

    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") StrategyCatalogQueryObject queryObject){
        queryObject.setPageSize(10);
        model.addAttribute("pageInfo",strategyCatalogService.selectForList(queryObject));
        model.addAttribute("strategies",strategyService.list());
        return "/strategyCatalog/list";
    }


    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        JSONResult result = new JSONResult();
        try {
            strategyCatalogService.saveOrUpdate(strategyCatalog);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
